// app.js

App({
  globalData: {
    baseUrl: 'https://www.rdcmy.com/rdc-recruit',
    groupIndex: 1
  },
  onLaunch() {
    const baseUrl = this.globalData.baseUrl;

    //  删除报名信息
    // wx.request({
    //   method: 'DELETE',
    //   url: baseUrl + '/test/deleteStuInfo?openId=' + wx.getStorageSync('openId'),
    //   success(e) {
    //     console.log(e);
    //   }
    // })

    // 检查是否有opneid 
    if (!wx.getStorageSync('openId')) {
      wx.setStorageSync('ifFirstTime', true)
    }
    wx.login({
      success: res => {
        wx.request({
          url: baseUrl + '/stuUser/getOpenId?code=' + res.code,
          success(e) {
            // console.log("session", e.data.data[0].session_key);
            // console.log(e.cookies[0]);
            wx.setStorageSync('cookie', e.cookies[0]);
            wx.setStorageSync('openId', e.data.data[0].openid)
            wx.setStorageSync('session', e.data.data[0].session_key)
            wx.setStorageSync('ifsign', e.data.msg === "无报名信息" ? 0 : 1)
          },
          fail(e) {
            wx.showToast({
              title: '请重新进入！',
              icon: 'error',
              duration: 1500
            })
          }
        })
      }
    })

    // request if hidden form
    wx.request({
      url: baseUrl + '/isDisplay',
      success(res) {
        // console.log('isShowPost', res.data)
        wx.setStorageSync("isShowPost", !res.data)
      }
    })
  },
})